using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using BeeldBank.Data;

namespace BeeldBank.Data.Sql
{
    /// <summary>
    /// MediaObjectBase - Provides Data Access methods for MediaObject.
    /// </summary>
    /// <remarks>Generated class: DO NOT MODIFY!</remarks>
    public class MediaObjectBase
    {
        /// <summary>
        /// Initializes a new instance of BeeldBank.Data.Base.MediaObjectDaoBase.
        /// </summary>
        public MediaObjectBase()
        {
        }

        #region Insert

        /// <summary>
        /// Insert a new record in the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to insert the MEDIAOBJECT table.</param>
        public static void Insert(DataRow dataRow)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            sqlConnection.Open();
            SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
            try
            {
                Insert(dataRow, sqlTransaction);
                sqlTransaction.Commit();
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        /// <summary>
        /// Insert a new record in the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to insert the MEDIAOBJECT table.</param>
        /// <param name="transaction">Transaction to execute the insert in.</param>
        public static void Insert(DataRow dataRow, System.Data.IDbTransaction transaction)
        {
            SqlTransaction sqlTransaction = (SqlTransaction)transaction;
            // Setup DataAdapter
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.InsertCommand = new SqlCommand();
            sqlDataAdapter.InsertCommand.Connection = sqlTransaction.Connection;
            sqlDataAdapter.InsertCommand.Transaction = sqlTransaction;
            sqlDataAdapter.InsertCommand.CommandText = "BEELDBANK_MEDIAOBJECT_INSERT";
            sqlDataAdapter.InsertCommand.CommandType = CommandType.StoredProcedure;

            // Add parameters
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.ReturnValue;
            sqlParameter.ParameterName = "@return";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Id
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Output;
            sqlParameter.ParameterName = "@id";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // StatusId
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@statusid";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["StatusId"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // TypeId
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@typeid";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["TypeId"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Titel
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@titel";
            sqlParameter.SqlDbType = SqlDbType.VarChar;
            sqlParameter.Value = dataRow["Titel"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // AltTekst
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@alttekst";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["AltTekst"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Omschrijving
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@omschrijving";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Omschrijving"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Datum_Realisatie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@datum_realisatie";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlParameter.Value = dataRow["Datum_Realisatie"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Trefwoorden
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@trefwoorden";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Trefwoorden"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Archiefnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@archiefnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Archiefnummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Subnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@subnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Subnummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Mapnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@mapnummer";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Mapnummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // DoosNummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@doosnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Doosnummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // HoesNummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@hoesnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Hoesnummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Vervaardiger
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@Vervaardiger";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Vervaardiger"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Collectie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@collectie";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Collectie"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Montage
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@montage";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Montage"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // FileNummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@filenummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["FileNummer"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // UseInBanner
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@useinbanner";
            sqlParameter.SqlDbType = SqlDbType.Bit;
            sqlParameter.Value = dataRow["UseInBanner"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Checked
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@checked";
            sqlParameter.SqlDbType = SqlDbType.Bit;
            sqlParameter.Value = dataRow["Checked"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Thumbnail
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@thumbnail";
            sqlParameter.SqlDbType = SqlDbType.Image;
            sqlParameter.Value = dataRow["Thumbnail"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Hoogte
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@hoogte";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Hoogte"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Latitude
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@latitude";
            sqlParameter.SqlDbType = SqlDbType.Float;
            sqlParameter.Value = dataRow["Latitude"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Longitude
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@longitude";
            sqlParameter.SqlDbType = SqlDbType.Float;
            sqlParameter.Value = dataRow["Longitude"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Lokatie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@lokatie";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Lokatie"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // CreatedByColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@createdby";
            sqlParameter.SqlDbType = SqlDbType.VarChar;
            sqlParameter.Value = dataRow["createdby"];
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // CreatedAtColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Output;
            sqlParameter.ParameterName = "@createdat";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // ModifiedByColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Output;
            sqlParameter.ParameterName = "@modifiedby";
            sqlParameter.SqlDbType = SqlDbType.VarChar;
            sqlParameter.Value = "";
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // ModifiedAtColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Output;
            sqlParameter.ParameterName = "@modifiedat";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlDataAdapter.InsertCommand.Parameters.Add(sqlParameter);

            // Execute Stored procedure
            try
            {
                sqlDataAdapter.InsertCommand.ExecuteNonQuery();
            }
            catch (Exception error)
            {
                sqlTransaction.Rollback();
                if (sqlDataAdapter.InsertCommand.Parameters["@return"].Value == null)
                {
                    throw new ApplicationException("Unexpected error.", error);
                }
                switch ((int)sqlDataAdapter.InsertCommand.Parameters["@return"].Value)
                {
                    case 0:
                        // Not an SQL error
                        throw new ApplicationException("Unexpected error.", error);
                    case 515:
                        int posStart = error.Message.IndexOf("NULL into column '");
                        int posEnd = error.Message.IndexOf("'", posStart + 18);
                        throw new NullNotAllowedException("MEDIAOBJECT. " + error.Message.Substring(posStart + 18, posEnd - posStart - 18));
                    case 2601:
                        throw new UniqueIndexException("MEDIAOBJECT");
                    case 50000:
                        throw new CustomException(error.Message);
                    default:
                        throw new ApplicationException("Unexpected Database error (" + ((int)sqlDataAdapter.InsertCommand.Parameters["@return"].Value).ToString() + ").", error);
                }
            }

            dataRow["Id"] = sqlDataAdapter.InsertCommand.Parameters["@id"].Value;

            dataRow["modifiedby"] = sqlDataAdapter.InsertCommand.Parameters["@modifiedby"].Value;
            dataRow["modifiedat"] = sqlDataAdapter.InsertCommand.Parameters["@modifiedat"].Value;
            dataRow["modifiedby"] = sqlDataAdapter.InsertCommand.Parameters["@modifiedby"].Value;
            dataRow["modifiedat"] = sqlDataAdapter.InsertCommand.Parameters["@modifiedat"].Value;
        }

        #endregion

        #region Update

        /// <summary>
        /// Update a record in the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to insert the MEDIAOBJECT table.</param>
        public static void Update(DataRow dataRow)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            sqlConnection.Open();
            SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
            try
            {
                Update(dataRow, sqlTransaction);
                sqlTransaction.Commit();
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        /// <summary>
        /// Update a record in the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to update.</param>
        /// <param name="transaction">Transaction to execute the insert in.</param>
        public static void Update(DataRow dataRow, System.Data.IDbTransaction transaction)
        {
            SqlTransaction sqlTransaction = (SqlTransaction)transaction;
            // Setup DataAdapter
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.UpdateCommand = new SqlCommand();
            sqlDataAdapter.UpdateCommand.Connection = sqlTransaction.Connection;
            sqlDataAdapter.UpdateCommand.Transaction = sqlTransaction;
            sqlDataAdapter.UpdateCommand.CommandText = "BEELDBANK_MEDIAOBJECT_UPDATE";
            sqlDataAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure;

            // Add parameters
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.ReturnValue;
            sqlParameter.ParameterName = "@return";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Id
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@id";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Id"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // StatusId
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@statusid";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["StatusId"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // TypeId
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@typeid";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["TypeId"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Titel
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@titel";
            sqlParameter.SqlDbType = SqlDbType.VarChar;
            sqlParameter.Value = dataRow["Titel"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // AltTekst
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@alttekst";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["AltTekst"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Omschrijving
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@omschrijving";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Omschrijving"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Datum_Realisatie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@datum_realisatie";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlParameter.Value = dataRow["Datum_Realisatie"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Trefwoorden
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@trefwoorden";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Trefwoorden"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Archiefnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@archiefnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Archiefnummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Subnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@subnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Subnummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Mapnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@mapnummer";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Mapnummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Vervaardiger
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@Vervaardiger";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Vervaardiger"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Collectie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@collectie";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Collectie"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Montage
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@montage";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Montage"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // FileNummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@filenummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["FileNummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // UseInBanner
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@useinbanner";
            sqlParameter.SqlDbType = SqlDbType.Bit;
            sqlParameter.Value = dataRow["UseInBanner"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Checked
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@checked";
            sqlParameter.SqlDbType = SqlDbType.Bit;
            sqlParameter.Value = dataRow["Checked"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Thumbnail
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@thumbnail";
            sqlParameter.SqlDbType = SqlDbType.Image;
            sqlParameter.Value = dataRow["Thumbnail"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Hoogte
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@hoogte";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Hoogte"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Latitude
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@latitude";
            sqlParameter.SqlDbType = SqlDbType.Float;
            sqlParameter.Value = dataRow["Latitude"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Longitude
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@longitude";
            sqlParameter.SqlDbType = SqlDbType.Float;
            sqlParameter.Value = dataRow["Longitude"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Lokatie
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@lokatie";
            sqlParameter.SqlDbType = SqlDbType.NVarChar;
            sqlParameter.Value = dataRow["Lokatie"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // ModifiedByColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@modifiedby";
            sqlParameter.SqlDbType = SqlDbType.VarChar;
            sqlParameter.Value = dataRow["modifiedby"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // ModifiedAtColumn
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Output;
            sqlParameter.ParameterName = "@modifiedat";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // VideoLengte
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@videolengte";
            sqlParameter.SqlDbType = SqlDbType.DateTime;
            sqlParameter.Value = dataRow["VideoLengte"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Doosnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@doosnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Doosnummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Hoesnummer
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@hoesnummer";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Hoesnummer"];
            sqlDataAdapter.UpdateCommand.Parameters.Add(sqlParameter);

            // Execute Stored procedure
            try
            {
                sqlDataAdapter.UpdateCommand.ExecuteNonQuery();
            }
            catch (Exception error)
            {
                sqlTransaction.Rollback();
                if (sqlDataAdapter.UpdateCommand.Parameters["@return"].Value == null)
                {
                    throw new ApplicationException("Unexpected error.", error);
                }
                switch ((int)sqlDataAdapter.UpdateCommand.Parameters["@return"].Value)
                {
                    case 0:
                        // Not an SQL error
                        throw new ApplicationException("Unexpected error.", error);
                    case 515:
                        int posStart = error.Message.IndexOf("NULL into column '");
                        int posEnd = error.Message.IndexOf("'", posStart + 18);
                        throw new NullNotAllowedException("MEDIAOBJECT." + error.Message.Substring(posStart + 18, posEnd - posStart - 18));
                    case 2601:
                        throw new UniqueIndexException("MEDIAOBJECT");
                    case 50000:
                        throw new CustomException(error.Message);
                    default:
                        throw new ApplicationException("Unexpected Database error (" + ((int)sqlDataAdapter.UpdateCommand.Parameters["@return"].Value).ToString() + ").", error);
                }
            }
            // Check if something was deleted.
            if ((int)sqlDataAdapter.UpdateCommand.Parameters["@return"].Value != 1)
            {
                sqlTransaction.Rollback();
                throw new ConcurrencyException("MEDIAOBJECT");
            }

            dataRow["modifiedby"] = sqlDataAdapter.UpdateCommand.Parameters["@modifiedby"].Value;
            dataRow["modifiedat"] = sqlDataAdapter.UpdateCommand.Parameters["@modifiedat"].Value;

        }

        #endregion

        #region Delete

        /// <summary>
        /// Delete a record from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to delete the MEDIAOBJECT table.</param>
        public static void Delete(DataRow dataRow)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            sqlConnection.Open();
            SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
            try
            {
                Delete(dataRow, sqlTransaction);
                sqlTransaction.Commit();
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        /// <summary>
        /// Delete a record from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data to delete.</param>
        /// <param name="transaction">Transaction to execute the insert in.</param>
        public static void Delete(DataRow dataRow, System.Data.IDbTransaction transaction)
        {
            SqlTransaction sqlTransaction = (SqlTransaction)transaction;
            // Setup DataAdapter
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.DeleteCommand = new SqlCommand();
            sqlDataAdapter.DeleteCommand.Connection = sqlTransaction.Connection;
            sqlDataAdapter.DeleteCommand.Transaction = sqlTransaction;
            sqlDataAdapter.DeleteCommand.CommandText = "BEELDBANK_MEDIAOBJECT_DELETE";
            sqlDataAdapter.DeleteCommand.CommandType = CommandType.StoredProcedure;

            // Add parameters
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.ReturnValue;
            sqlParameter.ParameterName = "@return";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlDataAdapter.DeleteCommand.Parameters.Add(sqlParameter);

            // Id
            sqlParameter = new SqlParameter();
            sqlParameter.Direction = ParameterDirection.Input;
            sqlParameter.ParameterName = "@id";
            sqlParameter.SqlDbType = SqlDbType.Int;
            sqlParameter.Value = dataRow["Id"];
            sqlDataAdapter.DeleteCommand.Parameters.Add(sqlParameter);

            // Execute Stored procedure
            try
            {
                sqlDataAdapter.DeleteCommand.ExecuteNonQuery();
            }
            catch (Exception error)
            {
                sqlTransaction.Rollback();
                switch ((int)sqlDataAdapter.DeleteCommand.Parameters["@return"].Value)
                {
                    case 0:
                        // Not an SQL error
                        throw new ApplicationException("Unexpected error.", error);
                    case 547:
                        int posStart = error.Message.IndexOf("table 'BEELDBANK_");
                        int length = "table 'BEELDBANK_".Length;
                        int posEnd = error.Message.IndexOf("'", posStart + length);
                        throw new DeleteConstraintException(error.Message.Substring(posStart + length, posEnd - posStart - length));
                    default:
                        throw new ApplicationException("Unexpected Database error.", error);
                }
            }
            // Check if something was deleted.
            if ((int)sqlDataAdapter.DeleteCommand.Parameters["@return"].Value != 1)
            {
                sqlTransaction.Rollback();
                throw new ConcurrencyException("MEDIAOBJECT");
            }
        }

        #endregion

        #region public static void Save(DataRow dataRow)
        /// <summary>
        /// Save changes from a DataRow to the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data save.</param>
        public static void Save(DataRow dataRow)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            sqlConnection.Open();
            SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
            try
            {
                Save(dataRow, sqlTransaction);
                sqlTransaction.Commit();
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        /// <summary>
        /// Save changes from a DataRow to the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataRow">DataRow containing the data save.</param>
        /// <param name="transaction">Transaction.</param>
        public static void Save(DataRow dataRow, System.Data.IDbTransaction transaction)
        {
            SqlTransaction sqlTransaction = (SqlTransaction)transaction;
            switch (dataRow.RowState)
            {
                case DataRowState.Added:
                    Insert(dataRow, sqlTransaction);
                    break;
                case DataRowState.Modified:
                    Update(dataRow, sqlTransaction);
                    break;
                case DataRowState.Deleted:
                    Delete(dataRow, sqlTransaction);
                    break;
                default:
                    // Do nothing: DataRowState.Detached or DataRowState.Unchanged
                    break;
            }
        }
        #endregion

        #region void Save(DataTable dataTable)
        /// <summary>
        /// Save changes from a DataTable to the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataTable">DataTable containing the data save.</param>
        public static void Save(DataTable dataTable)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            sqlConnection.Open();
            SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
            try
            {
                Save(dataTable, sqlTransaction);
                sqlTransaction.Commit();
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        /// <summary>
        /// Save changes from a DataTable to the MEDIAOBJECT table.
        /// </summary>
        /// <param name="dataTable">DataTable containing the data save.</param>
        /// <param name="transaction">Transaction.</param>
        public static void Save(DataTable dataTable, System.Data.IDbTransaction transaction)
        {
            SqlTransaction sqlTransaction = (SqlTransaction)transaction;
            DataTable insertTable = dataTable.GetChanges(DataRowState.Added);
            if (insertTable != null && insertTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in insertTable.Rows)
                {
                    Insert(dataRow, sqlTransaction);
                }
            }

            DataTable updateTable = dataTable.GetChanges(DataRowState.Modified);
            if (updateTable != null && updateTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in updateTable.Rows)
                {
                    Update(dataRow, sqlTransaction);
                }
            }

            DataTable deleteTable = dataTable.GetChanges(DataRowState.Deleted);
            if (deleteTable != null && deleteTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in deleteTable.Rows)
                {
                    Delete(dataRow, sqlTransaction);
                }
            }
            return;
        }
        #endregion

        #region public static DataTable New()
        /// <summary>
        /// Create an empty DataTable with columns for the MEDIAOBJECT table.
        /// </summary>
        public static DataTable New()
        {
            DataTable dataTable = new DataTable("MEDIAOBJECT");
            dataTable.Columns.Add("Id", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("StatusId", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("TypeId", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Titel", System.Type.GetType("System.String"));
            dataTable.Columns.Add("AltTekst", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Omschrijving", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Datum_Realisatie", System.Type.GetType("System.DateTime"));
            dataTable.Columns.Add("Trefwoorden", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Archiefnummer", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Subnummer", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Mapnummer", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Doosnummer", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Hoesnummer", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Vervaardiger", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Lokatie", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Hoogte", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("Latitude", System.Type.GetType("System.Double"));
            dataTable.Columns.Add("Longitude", System.Type.GetType("System.Double"));
            dataTable.Columns.Add("Collectie", System.Type.GetType("System.String"));
            dataTable.Columns.Add("Montage", System.Type.GetType("System.String"));
            dataTable.Columns.Add("FileNummer", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("UseInBanner", System.Type.GetType("System.Boolean"));
            dataTable.Columns.Add("Thumbnail", System.Type.GetType("System.Byte[]"));
            dataTable.Columns.Add("Checked", System.Type.GetType("System.Boolean"));
            dataTable.Columns.Add("VideoLengte", System.Type.GetType("System.DateTime"));
            dataTable.Columns.Add("TridionId", System.Type.GetType("System.String"));
            dataTable.Columns.Add("GroepRechten", System.Type.GetType("System.Int32"));
            
            dataTable.Columns.Add("MediaObjectId", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("CultureInfoId", System.Type.GetType("System.Int32"));
            dataTable.Columns.Add("createdby", System.Type.GetType("System.String"));
            dataTable.Columns.Add("createdat", System.Type.GetType("System.DateTime"));
            dataTable.Columns.Add("modifiedby", System.Type.GetType("System.String"));
            dataTable.Columns.Add("modifiedat", System.Type.GetType("System.DateTime"));

            return dataTable;
        }
        #endregion

        #region protected DataTable Open(string storedProcedureName, SqlParameter sqlParameter)

        /// <summary>
        /// Creates a DataTable with data from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="storedProcedureName">Name of the Stored Procedure that is used to retrieve the data.</param>
        /// <param name="sqlParameter">Parameter that contains the argument for the Stored Procedure.</param>
        protected static DataTable Open(string storedProcedureName, SqlParameter sqlParameter)
        {
            return Open(storedProcedureName, sqlParameter, null);
        }

        /// <summary>
        /// Creates a DataTable with data from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="storedProcedureName">Name of the Stored Procedure that is used to retrieve the data.</param>
        /// <param name="sqlParameters">Parameter array that contains the argument for the Stored Procedure.</param>
        protected static DataTable OpenParamArray(string storedProcedureName, SqlParameter[] sqlParameters)
        {
            return OpenParamArray(storedProcedureName, sqlParameters, null);
        }

        /// <summary>
        /// Fills a DataTable with data from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="storedProcedureName">Name of the Stored Procedure that is used to retrieve the data.</param>
        /// <param name="sqlParameter">Parameter that contains the argument for the Stored Procedure.</param>
        /// <param name="dataTable">Datatable that is filled. If null, a new DataTable is created.</param>
        protected static DataTable Open(string storedProcedureName, SqlParameter sqlParameter, DataTable dataTable)
        {
            SqlParameter[] sqlParameters;

            if (sqlParameter != null)
            {
                sqlParameters = new SqlParameter[1];
                sqlParameters[0] = sqlParameter;
            }
            else
            {
                sqlParameters = new SqlParameter[0];
            }

            return OpenParamArray(storedProcedureName, sqlParameters, dataTable);
        }


        /// <summary>
        /// Fills a DataTable with data from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="storedProcedureName">Name of the Stored Procedure that is used to retrieve the data.</param>
        /// <param name="sqlParameters">Parameter array that contains the arguments for the Stored Procedure.</param>
        /// <param name="dataTable">Datatable that is filled. If null, a new DataTable is created.</param>
        protected static DataTable OpenParamArray(string storedProcedureName, SqlParameter[] sqlParameters, DataTable dataTable)
        {
            // Setup Connection
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.AppSettings["connectstringSql"];
            // Setup DataAdapter
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = new SqlCommand();
            sqlDataAdapter.SelectCommand.Connection = sqlConnection;
            sqlDataAdapter.SelectCommand.CommandText = storedProcedureName;
            sqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            // Add parameters
            foreach (SqlParameter sqlParameter in sqlParameters)
            {
                sqlDataAdapter.SelectCommand.Parameters.Add(sqlParameter);
            }

            // Fill dataset
            if (dataTable == null)
            {
                dataTable = new DataTable("MediaObject");
            }
            sqlConnection.Open();
            try
            {
                sqlDataAdapter.Fill(dataTable);
            }
            catch (SqlException)
            {
                sqlConnection.Close();
                sqlConnection.Open();
                try
                {
                    sqlDataAdapter.Fill(dataTable);
                }
                catch
                {
                }
                return dataTable;
            }
            finally
            {
                sqlConnection.Close();
            }
            return dataTable;
        }
        #endregion

        #region Open methods

        /// <summary>
        /// Creates a DataTable containing all records and all fields from the MEDIAOBJECT table.
        /// </summary>
        public static DataTable Open()
        {
            return Open("BEELDBANK_MEDIAOBJECT_SELECT", null);
        }

        /// <summary>
        /// Fills a DataTable with all records and all fields from the MEDIAOBJECT table.
        /// </summary>
        public static DataTable Open(DataTable dataTable)
        {
            return Open("BEELDBANK_MEDIAOBJECT_SELECT", null, dataTable);
        }


        /// <summary>
        /// Creates a DataTable containing all records with the primary key column and the label columns from the MEDIAOBJECT table.
        /// </summary>
        public static DataTable OpenDropDown()
        {
            return Open("BEELDBANK_MEDIAOBJECT_SELECT_DROPDOWN", null);
        }

        /// <summary>
        /// Fills a DataTable with all records with the primary key column and the label columns from the MEDIAOBJECT table.
        /// </summary>
        public static DataTable OpenDropDown(DataTable dataTable)
        {
            return Open("BEELDBANK_MEDIAOBJECT_SELECT_DROPDOWN", null, dataTable);
        }
        /// <summary>
        /// Creates a DataTable containing the record specified by the primary key from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="Id">Primary key value used to retrieve the record.</param>
        public static DataTable Open(int Id)
        {
            return Open(Id, null);
        }

        /// <summary>
        /// Fills a DataTable with the record specified by the primary key from the MEDIAOBJECT table.
        /// </summary>
        /// <param name="Id">Primary key value used to retrieve the record.</param>
        /// <param name="dataTable">DataTable to be filled.</param>
        public static DataTable Open(int Id, DataTable dataTable)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@id", SqlDbType.Int);
            sqlParameter.Value = Id;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_FROM_ID", sqlParameter, dataTable);
        }
        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with StatusId as specified in the argument.
        /// </summary>
        /// <param name="StatusId">Argument that is used to retrieve the data.</param>
        public static DataTable OpenFromStatusId(int StatusId)
        {
            return OpenFromStatusId(StatusId, null);
        }

        /// <summary>
        /// Fills a DataTable with records from the BEELDBANK_MEDIAOBJECT table with StatusId as specified in the argument.
        /// </summary>
        /// <param name="StatusId">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable to be filled.</param>
        public static DataTable OpenFromStatusId(int StatusId, DataTable dataTable)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@statusid", SqlDbType.Int);
            sqlParameter.Value = StatusId;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_FROM_STATUSID", sqlParameter, dataTable);
        }
        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with TypeId as specified in the argument.
        /// </summary>
        /// <param name="TypeId">Argument that is used to retrieve the data.</param>
        public static DataTable OpenFromTypeId(int TypeId)
        {
            return OpenFromTypeId(TypeId, null);
        }

        /// <summary>
        /// Fills a DataTable with records from the BEELDBANK_MEDIAOBJECT table with TypeId as specified in the argument.
        /// </summary>
        /// <param name="TypeId">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable to be filled.</param>
        public static DataTable OpenFromTypeId(int TypeId, DataTable dataTable)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@typeid", SqlDbType.Int);
            sqlParameter.Value = TypeId;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_FROM_TYPEID", sqlParameter, dataTable);
        }
        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with Titel as specified in the argument.
        /// </summary>
        /// <param name="Titel">Argument that is used to retrieve the data.</param>
        public static DataTable OpenFromTitel(string Titel)
        {
            return OpenFromTitel(Titel, null);
        }

        /// <summary>
        /// Fills a DataTable with records from the BEELDBANK_MEDIAOBJECT table with Titel as specified in the argument.
        /// </summary>
        /// <param name="Titel">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable to be filled.</param>
        public static DataTable OpenFromTitel(string Titel, DataTable dataTable)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@titel", SqlDbType.VarChar);
            sqlParameter.Value = Titel;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_FROM_TITEL", sqlParameter, dataTable);
        }

        /// <summary>
        /// Fills a DataTable with records from the BEELDBANK_MEDIAOBJECT table with Archiefnummer as specified in the argument.
        /// </summary>
        /// <param name="Archiefnummer">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable to be filled.</param>
        public static DataTable OpenFromArchiefnummer(int Archiefnummer, DataTable dataTable)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@archiefnummer", SqlDbType.Int);
            sqlParameter.Value = Archiefnummer;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_FROM_ARCHIEFNUMMER", sqlParameter, dataTable);
        }

        #endregion

        #region Show methods
        /// <summary>
        /// Creates a DataTable containing all records and all fields from the MEDIAOBJECT table completed with the label fields of associated tables.
        /// </summary>
        public static DataTable Show()
        {
            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW", null);
        }
        /// <summary>
        /// Creates a DataTable containing the record specified by the primary key from the MEDIAOBJECT> table completed with the label fields of associated tables.
        /// </summary>
        /// <param name="Id">Primary key values used to retrieve the record.</param>
        public static DataTable Show(int Id)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@id", SqlDbType.Int);
            sqlParameter.Value = Id;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_ID", sqlParameter);
        }
        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with StatusId as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="StatusId">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromStatusId(int StatusId)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@statusid", SqlDbType.Int);
            sqlParameter.Value = StatusId;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_STATUSID", sqlParameter);
        }

        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with TypeId as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="TypeId">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromTypeId(int TypeId, string UserName, int PageIndex, int PageSize, int OrderBy, out int TotalRecords)
        {
            SqlParameter[] sqlParamArray = new SqlParameter[6];

            sqlParamArray[0] = new SqlParameter("@typeid", SqlDbType.Int);
            sqlParamArray[0].Value = TypeId;

            sqlParamArray[1] = new SqlParameter("@username", SqlDbType.VarChar);
            sqlParamArray[1].Value = UserName;
            sqlParamArray[1].Size = UserName.Length;

            if (PageIndex == -1)
            {
                PageIndex = 0;
                PageSize = int.MaxValue;
            }

            sqlParamArray[2] = new SqlParameter("@PageIndex", SqlDbType.Int);
            sqlParamArray[2].Value = PageIndex;

            sqlParamArray[3] = new SqlParameter("@PageSize", SqlDbType.Int);
            sqlParamArray[3].Value = PageSize;

            sqlParamArray[4] = new SqlParameter("@OrderBy", SqlDbType.Int);
            sqlParamArray[4].Value = OrderBy;

            sqlParamArray[5] = new SqlParameter("@RowsReturned", SqlDbType.Int);
            sqlParamArray[5].Value = 0;
            sqlParamArray[5].Direction = ParameterDirection.InputOutput;

            DataTable dt = OpenParamArray("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_TYPEID", sqlParamArray, null);
            TotalRecords = (int)sqlParamArray[5].Value;

            return dt;
        }
        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with Titel as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="Titel">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromTitel(string Titel)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@titel", SqlDbType.VarChar);
            sqlParameter.Value = Titel;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_TITEL", sqlParameter);
        }

        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with Archiefnummer as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="Archiefnummer">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromArchiefnummer(int Archiefnummer)
        {
            SqlParameter sqlParameter;
            sqlParameter = new SqlParameter("@archiefnummer", SqlDbType.Int);
            sqlParameter.Value = Archiefnummer;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_ARCHIEFNUMMER", sqlParameter);
        }

        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with Collectie as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="Collectie">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromCollectie(string Collectie)
        {
            SqlParameter sqlParameter;

            sqlParameter = new SqlParameter("@Collectie", SqlDbType.VarChar);
            sqlParameter.Value = Collectie;
            sqlParameter.Size = Collectie.Length;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_COLLECTIE", sqlParameter);
        }

        /// <summary>
        /// Creates a DataTable containing records from the BEELDBANK_MEDIAOBJECT table with Collectie as specified in the argument completed with the label fields of associated tables.
        /// </summary>
        /// <param name="Collectie">Argument that is used to retrieve the data.</param>
        public static DataTable ShowFromPartOfCollectie(string Collectie)
        {
            SqlParameter sqlParameter;

            sqlParameter = new SqlParameter("@Collectie", SqlDbType.VarChar);
            sqlParameter.Value = Collectie;
            sqlParameter.Size = Collectie.Length;

            return Open("BEELDBANK_MEDIAOBJECT_SELECT_SHOW_FROM_PART_OF_COLLECTIE", sqlParameter);
        }
        #endregion

        /// <summary>
        /// Fills a DataTable with records from the MEDIAOBJECT
        /// </summary>
        /// <param name="UseInBanner">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable that is filled.</param>
        public static DataTable OpenUseInBanner(bool UseInBanner, DataTable dataTable)
        {
            SqlParameter[] sqlParameters;
            sqlParameters = new SqlParameter[1];

            SqlParameter sqlParameter1;
            sqlParameter1 = new SqlParameter("@useinbanner", SqlDbType.Bit);
            sqlParameter1.Value = UseInBanner;
            sqlParameters[0] = sqlParameter1;

            return OpenParamArray("BEELDBANK_MEDIAOBJECT_SELECT_USEINBANNER", sqlParameters, dataTable);
        }

        /// <summary>
        /// Creates a DataTable containing records from the MEDIAOBJECT table with UseInBanner as specified in the arguments completed with the label fields of associated tables.
        /// </summary>
        /// <param name="UseInBanner">Argument that is used to retrieve the data.</param>
        public static DataTable OpenUseInBanner(bool UseInBanner)
        {
            SqlParameter[] sqlParameters;
            sqlParameters = new SqlParameter[1];

            SqlParameter sqlParameter1;
            sqlParameter1 = new SqlParameter("@useinbanner", SqlDbType.Bit);
            sqlParameter1.Value = UseInBanner;
            sqlParameters[0] = sqlParameter1;

            return OpenParamArray("BEELDBANK_MEDIAOBJECT_SELECT_USEINBANNER", sqlParameters);
        }

        /// <summary>
        /// Fills a DataTable with records from the MEDIAOBJECT
        /// </summary>
        /// <param name="FileNummer">Argument that is used to retrieve the data.</param>
        /// <param name="dataTable">DataTable that is filled.</param>
        public static DataTable OpenFileNummer(int FileNummer, DataTable dataTable)
        {
            SqlParameter[] sqlParameters;
            sqlParameters = new SqlParameter[1];

            SqlParameter sqlParameter1;
            sqlParameter1 = new SqlParameter("@filenummer", SqlDbType.Int);
            sqlParameter1.Value = FileNummer;
            sqlParameters[0] = sqlParameter1;

            return OpenParamArray("BEELDBANK_MEDIAOBJECT_SELECT_FILENUMMER", sqlParameters, dataTable);
        }

        /// <summary>
        /// Creates a DataTable containing records from the MEDIAOBJECT table with FileNummer as specified in the arguments completed with the label fields of associated tables.
        /// </summary>
        /// <param name="FileNummer">Argument that is used to retrieve the data.</param>
        public static DataTable OpenFileNummer(int FileNummer)
        {
            SqlParameter[] sqlParameters;
            sqlParameters = new SqlParameter[1];

            SqlParameter sqlParameter1;
            sqlParameter1 = new SqlParameter("@filenummer", SqlDbType.Int);
            sqlParameter1.Value = FileNummer;
            sqlParameters[0] = sqlParameter1;

            return OpenParamArray("BEELDBANK_MEDIAOBJECT_SELECT_FILENUMMER", sqlParameters);
        }
    }
}
